home *** CD-ROM | disk | FTP | other *** search
- /* ----------------------------------------------------------------------
-
- Launcher
-
- Written by: Paul Celestin
-
- 950314 - 1.0.0 - absolute first version
- 950321 - 1.0.1 - work continues to add a few more features
- 950808 - 1.1.0 - added ability to open ConfigPPP
- 951213 - 1.1.1 - fixed (maybe) crashing bug when launching apps
- 960704 - 1.1.2 - updated to compile with CW9
-
- ---------------------------------------------------------------------- */
-
-
- /* ----------------------------------------------------------------------
- includes
- ---------------------------------------------------------------------- */
-
- #include "the_defines.h"
- #include "the_globals.h"
- #include "the_prototypes.h"
- #include "pppcontrol.h"
-
- Boolean gDone,
- gWNEImplemented,
- gInBackground;
- int gNumApps;
- EventRecord gTheEvent;
- MenuHandle gAppleMenu,
- gFileMenu;
- WindowPtr gTheWindow;
- PixPatHandle gPixPat;
- ProcessSerialNumber gMailApp,
- gNewsApp,
- gFTPApp,
- gWebApp,
- gTelnetApp;
-
- /* ----------------------------------------------------------------------
- main - here is where it all began...
- ---------------------------------------------------------------------- */
- void main()
- {
- InitToolBox();
- InitMenuBar();
- MainLoop();
- ExitToShell();
- }
-
-
- /* ----------------------------------------------------------------------
- InitToolBox
- ---------------------------------------------------------------------- */
- void InitToolBox()
- {
- InitGraf(&qd.thePort);
- InitFonts();
- FlushEvents(everyEvent, 0);
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(0L);
- InitCursor();
- }
-
-
- /* ----------------------------------------------------------------------
- InitMenuBar
- ---------------------------------------------------------------------- */
- void InitMenuBar()
- {
- Handle myMenuBar;
-
- myMenuBar = GetNewMBar(MENU_BASE_ID);
- if (myMenuBar == NIL)
- SysBeep(1);
- else
- SetMenuBar(myMenuBar);
-
- gAppleMenu = GetMHandle(MENU_APPLE_ID);
- if (gAppleMenu == NIL)
- SysBeep(1);
- else
- AddResMenu(gAppleMenu,'DRVR');
-
- gFileMenu = GetMHandle(MENU_FILE_ID);
- if (gFileMenu == NIL)
- SysBeep(1);
-
- DrawMenuBar();
- }
-
-
- /* ----------------------------------------------------------------------
- MainLoop
- ---------------------------------------------------------------------- */
- void MainLoop()
- {
- RgnHandle cursorRgn;
- Boolean gotEvent;
- WindowRecord *myWinRecord;
- Rect myWinRect;
- Str255 myTitle;
-
- gInBackground = false;
-
- cursorRgn = NewRgn();
-
- gWNEImplemented = (NGetTrapAddress(WNE_TRAP_NUM,ToolTrap) !=
- NGetTrapAddress(UNIMPL_TRAP_NUM,ToolTrap));
-
- gPixPat = GetPixPat(SYSTEM_PPAT);
-
- myWinRect = qd.screenBits.bounds;
- myWinRecord = NIL;
- gTheWindow =
- NewCWindow(myWinRecord,&myWinRect,"\p",FALSE,plainDBox,(WindowPtr)-1L,FALSE,0L);
-
- if (gTheWindow)
- {
- DrawButtons();
- ShowWindow(gTheWindow);
- DoUpdate();
-
- gDone = false;
-
- while (gDone == false)
- {
- if (gWNEImplemented)
- gotEvent = WaitNextEvent(everyEvent,&gTheEvent,MIN_SLEEP,cursorRgn);
- else
- {
- SystemTask();
- gotEvent = GetNextEvent(everyEvent,&gTheEvent);
- }
-
- if (gotEvent)
- Do();
- }
- QuitAllApps();
- }
- }
-
-
- /* ----------------------------------------------------------------------
- DrawButtons
- ---------------------------------------------------------------------- */
- void DrawButtons()
- {
- ControlHandle hPPP, hMail, hNews, hFTP, hWeb, hTelnet;
- Rect tRect;
- short theCenter,numButtons,buttonWidth,
- stripWidth,curPosition,theTop;
-
- tRect = qd.screenBits.bounds;
- theCenter = tRect.right / 2;
- numButtons = 6;
- buttonWidth = 64;
- stripWidth = numButtons * buttonWidth;
- curPosition = theCenter - (stripWidth / 2);
- theTop = (tRect.bottom / 1.5);
-
- tRect.top = theTop;
- tRect.bottom = tRect.top + 64;
- tRect.left = curPosition;
- tRect.right = curPosition + buttonWidth;
- hPPP = NewControl(gTheWindow,&tRect,"\pConfig PPP",1,PPP_CONTROL,0,0,577,0);
- curPosition = curPosition + buttonWidth;
-
- tRect.top = theTop;
- tRect.bottom = tRect.top + 64;
- tRect.left = curPosition;
- tRect.right = curPosition + buttonWidth;
- hMail = NewControl(gTheWindow,&tRect,"\pMail",1,MAIL_CONTROL,0,0,577,0);
- curPosition = curPosition + buttonWidth;
-
- tRect.top = theTop;
- tRect.bottom = tRect.top + 64;
- tRect.left = curPosition;
- tRect.right = curPosition + buttonWidth;
- hNews = NewControl(gTheWindow,&tRect,"\pNews",1,NEWS_CONTROL,0,0,577,0);
- curPosition = curPosition + buttonWidth;
-
- tRect.top = theTop;
- tRect.bottom = tRect.top + 64;
- tRect.left = curPosition;
- tRect.right = curPosition + buttonWidth;
- hFTP = NewControl(gTheWindow,&tRect,"\pFTP",1,FTP_CONTROL,0,0,577,0);
- HLock((Handle)hFTP);
- curPosition = curPosition + buttonWidth;
-
- tRect.top = theTop;
- tRect.bottom = tRect.top + 64;
- tRect.left = curPosition;
- tRect.right = curPosition + buttonWidth;
- hWeb = NewControl(gTheWindow,&tRect,"\pWeb",1,WEB_CONTROL,0,0,577,0);
- curPosition = curPosition + buttonWidth;
-
- tRect.top = theTop;
- tRect.bottom = tRect.top + 64;
- tRect.left = curPosition;
- tRect.right = curPosition + buttonWidth;
- hTelnet = NewControl(gTheWindow,&tRect,"\pTelnet",1,TELNET_CONTROL,0,0,577,0);
- curPosition = curPosition + buttonWidth;
- }
-
-
- /* ----------------------------------------------------------------------
- Do
- ---------------------------------------------------------------------- */
- void Do()
- {
- char c;
-
- switch (gTheEvent.what)
- {
- case nullEvent:
- break;
- case mouseDown:
- DoMouseDown();
- break;
- case keyDown:
- case autoKey:
- c = gTheEvent.message & charCodeMask;
- if ((gTheEvent.modifiers & cmdKey) != 0)
- {
- DoMenu(MenuKey(c));
- }
- break;
- case activateEvt:
- DoUpdate();
- break;
- case updateEvt:
- DoUpdate();
- break;
- case app4Evt:
- if ((gTheEvent.message & SUSPEND_RESUME_BIT) == RESUMING)
- gInBackground = (gTheEvent.message & 0x01) == 0;
- break;
- }
- }
-
- /* ----------------------------------------------------------------------
- DoUpdate
- ---------------------------------------------------------------------- */
- void DoUpdate()
- {
- GrafPtr savedPort;
- Rect theRect,pictRect;
- PicHandle thePicture;
-
- SetCursor(&qd.arrow);
- GetPort(&savedPort);
- SetPort(gTheWindow);
- BeginUpdate(gTheWindow);
- SetRect(&theRect,gTheWindow->portRect.left,
- gTheWindow->portRect.top,
- gTheWindow->portRect.right,
- gTheWindow->portRect.bottom);
- if (gPixPat != NIL)
- FillCRect(&theRect,gPixPat);
-
- if ((thePicture = GetPicture(BACKGROUND_PICT)) != NIL)
- {
- pictRect = (**(thePicture)).picFrame;
- pictRect.left = (theRect.right / 2) - (pictRect.right / 2);
- pictRect.right = pictRect.left + pictRect.right;
- pictRect.top = (theRect.bottom / 4) - (pictRect.bottom / 4);
- pictRect.bottom = (pictRect.top + pictRect.bottom);
- DrawPicture(thePicture,&pictRect);
- }
- DrawControls(gTheWindow);
- EndUpdate(gTheWindow);
- SetPort(savedPort);
- HPurge((Handle)thePicture);
- }
-
- /* ----------------------------------------------------------------------
- DoMouseDown
- ---------------------------------------------------------------------- */
- void DoMouseDown()
- {
- WindowPtr window;
- short int thePart;
- long int menuChoice, windSize, newSize;
- Boolean doZoom, doGoAway;
- Point p;
-
- thePart = FindWindow(gTheEvent.where,&window);
- switch (thePart)
- {
- case inMenuBar:
- menuChoice = MenuSelect(gTheEvent.where);
- DoMenu(menuChoice);
- break;
- case inSysWindow:
- SystemClick(&gTheEvent,window);
- break;
- case inContent:
- if (window != FrontWindow())
- SelectWindow(window);
- else
- {
- p = gTheEvent.where;
- GlobalToLocal(&p);
- DoWindow(p);
- }
- break;
- default:
- break;
- }
- }
-
- /* ----------------------------------------------------------------------
- DoMenu
- ---------------------------------------------------------------------- */
- void DoMenu(menuChoice)
- long int menuChoice;
- {
- int theMenu;
- int theItem;
-
- if (menuChoice != 0)
- {
- theMenu = HiWord(menuChoice);
- theItem = LoWord(menuChoice);
- switch (theMenu)
- {
- case MENU_APPLE_ID:
- DoMenuApple(theItem);
- break;
- case MENU_FILE_ID:
- DoMenuFile(theItem);
- break;
- default:
- break;
- }
- HiliteMenu(0);
- }
- }
-
- /* ----------------------------------------------------------------------
- DoWindow
- ---------------------------------------------------------------------- */
- void DoWindow(Point p)
- {
- short choice;
- ControlHandle control;
- CursHandle theCursor;
-
- if (FindControl(p,gTheWindow,&control))
- {
- if (TrackControl(control,p,NIL))
- {
- theCursor = GetCursor(4);
- HLock((Handle)theCursor);
- SetCursor(*theCursor);
- HUnlock((Handle)theCursor);
-
- choice = GetCtlValue(control);
-
- switch (choice)
- {
- case PPP_CONTROL:
- DoPPP();
- break;
- case MAIL_CONTROL:
- DoMail();
- break;
- case NEWS_CONTROL:
- DoNews();
- break;
- case FTP_CONTROL:
- DoFTP();
- break;
- case WEB_CONTROL:
- DoWeb();
- break;
- case TELNET_CONTROL:
- DoTelnet();
- break;
- default:
- break;
- }
- }
- }
- }
-
-
- /* ----------------------------------------------------------------------
- DoPPP
- ---------------------------------------------------------------------- */
- void DoPPP()
- {
- short vRefNum;
- long dirID;
- FSSpec theApp;
- OSErr myErr;
-
- myErr = FindFolder(kOnSystemDisk, kControlPanelFolderType,
- kDontCreateFolder, &vRefNum, &dirID);
- if (myErr != noErr)
- {
- SysBeep(1);
- return;
- }
- myErr = LocateFile(TYPE_CDEV, CREATOR_PPP, vRefNum, &theApp);
- if (myErr != noErr)
- {
- SysBeep(1);
- return;
- }
- myErr = OpenCP(theApp, CREATOR_PPP);
- if (myErr != noErr)
- {
- SysBeep(1);
- return;
- }
- }
-
-
- /* ----------------------------------------------------------------------
- DoMail
- ---------------------------------------------------------------------- */
- void DoMail()
- {
- FSSpec theApp;
-
- if (LocateFile('APPL', CREATOR_MAIL, 0, &theApp) == noErr)
- if (LaunchIt(theApp,&gMailApp) != noErr)
- SysBeep(1);
- }
-
-
- /* ----------------------------------------------------------------------
- DoNews
- ---------------------------------------------------------------------- */
- void DoNews()
- {
- FSSpec theApp;
-
- if (!pppup())
- pppopen();
- if (LocateFile('APPL', CREATOR_NEWS, 0, &theApp) == noErr)
- if (LaunchIt(theApp,&gNewsApp) != noErr)
- SysBeep(1);
- }
-
-
- /* ----------------------------------------------------------------------
- DoFTP
- ---------------------------------------------------------------------- */
- void DoFTP()
- {
- FSSpec theApp;
-
- if (!pppup())
- pppopen();
- if (LocateFile('APPL', CREATOR_FTP, 0, &theApp) == noErr)
- if (LaunchIt(theApp,&gFTPApp) != noErr)
- SysBeep(1);
- }
-
-
- /* ----------------------------------------------------------------------
- DoWeb
- ---------------------------------------------------------------------- */
- void DoWeb()
- {
- FSSpec theApp;
-
- if (!pppup())
- pppopen();
- if (LocateFile('APPL', CREATOR_WEB, 0, &theApp) == noErr)
- if (LaunchIt(theApp,&gWebApp) != noErr)
- SysBeep(1);
- }
-
-
- /* ----------------------------------------------------------------------
- DoTelnet
- ---------------------------------------------------------------------- */
- void DoTelnet()
- {
- FSSpec theApp;
-
- if (!pppup())
- pppopen();
- if (LocateFile('APPL', CREATOR_TELNET, 0, &theApp) == noErr)
- if (LaunchIt(theApp,&gTelnetApp) != noErr)
- SysBeep(1);
- }
-
-
- /* ----------------------------------------------------------------------
- QuitAllApps
- ---------------------------------------------------------------------- */
- void QuitAllApps()
- {
- CursHandle theCursor;
-
- theCursor = GetCursor(4);
- HLock((Handle)theCursor);
- SetCursor(*theCursor);
- HUnlock((Handle)theCursor);
-
- QuitIt(&gMailApp);
- QuitIt(&gNewsApp);
- QuitIt(&gFTPApp);
- QuitIt(&gWebApp);
- QuitIt(&gTelnetApp);
- if (pppup())
- pppclose(1);
- }